package com.js.basic.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.js.basic.domain.BsContractAgree;
import com.js.basic.service.IBsContractAgreeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 合同约定Controller
 * 
 * @author ruoyi
 * @date 20240709
 */
@RestController
@RequestMapping("/agree")
public class BsContractAgreeController extends BaseController
{
    @Autowired
    private IBsContractAgreeService bsContractAgreeService;

    /**
     * 查询合同约定列表
     */
    @RequiresPermissions("basic:agree:list")
    @GetMapping("/list")
    public TableDataInfo list(BsContractAgree bsContractAgree)
    {
        startPage();
        List<BsContractAgree> list = bsContractAgreeService.selectBsContractAgreeList(bsContractAgree);
        return getDataTable(list);
    }

    /**
     * 导出合同约定列表
     */
    @RequiresPermissions("basic:agree:export")
    @Log(title = "合同约定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BsContractAgree bsContractAgree)
    {
        List<BsContractAgree> list = bsContractAgreeService.selectBsContractAgreeList(bsContractAgree);
        ExcelUtil<BsContractAgree> util = new ExcelUtil<BsContractAgree>(BsContractAgree.class);
        util.exportExcel(response, list, "合同约定数据");
    }

    /**
     * 获取合同约定详细信息
     */
    @RequiresPermissions("basic:agree:query")
    @GetMapping(value = "/{agreeId}")
    public AjaxResult getInfo(@PathVariable("agreeId") Long agreeId)
    {
        return success(bsContractAgreeService.selectBsContractAgreeByAgreeId(agreeId));
    }

    /**
     * 新增合同约定
     */
    @RequiresPermissions("basic:agree:add")
    @Log(title = "合同约定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BsContractAgree bsContractAgree)
    {
        return toAjax(bsContractAgreeService.insertBsContractAgree(bsContractAgree));
    }

    /**
     * 修改合同约定
     */
    @RequiresPermissions("basic:agree:edit")
    @Log(title = "合同约定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BsContractAgree bsContractAgree)
    {
        return toAjax(bsContractAgreeService.updateBsContractAgree(bsContractAgree));
    }

    /**
     * 删除合同约定
     */
    @RequiresPermissions("basic:agree:remove")
    @Log(title = "合同约定", businessType = BusinessType.DELETE)
	@DeleteMapping("/{agreeIds}")
    public AjaxResult remove(@PathVariable Long[] agreeIds)
    {
        return toAjax(bsContractAgreeService.deleteBsContractAgreeByAgreeIds(agreeIds));
    }
}
